{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## This example shows Simulated Anealing on the benchmark data. \n",
    "http://decsai.ugr.es/~casillas/fmlib/ele2-4-1056.html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import csv\n",
    "import os\n",
    "import sys\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "import time\n",
    "\n",
    "# add path of needed code \n",
    "parent_directory = os.path.abspath('..')\n",
    "sys.path.append(parent_directory+'/Code/')\n",
    "\n",
    "from Fuzzification import cluster, scale\n",
    "import Reader\n",
    "import FIS\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "path = parent_directory +'/Data/elec/'\n",
    "file = 'ele2-4-1056-5.tra'\n",
    "data = Reader.read_elec_data(path, file)\n",
    "# The target column of your data\n",
    "target_col = -1 # last column"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# specify overlap of your sets, or the variance of the gaussian\n",
    "overlap = 0.01\n",
    "# Gaussian, triangle or trapezoid\n",
    "mf = 'Gaussian'\n",
    "# number of clusters per feature\n",
    "Ncentroids = [10, 15, 25, 25, 45]\n",
    "# A name for the FIS file\n",
    "FIS_name='Demo_WM_elec'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## First test without SA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The training took:  0.7852380275726318 seconds\n"
     ]
    }
   ],
   "source": [
    "# train the FIS \n",
    "start = time.time()\n",
    "FIS.train(FIS_name, data, target_col, mf, Ncentroids, overlap)\n",
    "print('The training took: ', time.time() - start, 'seconds')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# read in the trained FIS\n",
    "method, mf, overlap, target_centroids, feature_centroids, RB = FIS.read(FIS_name +'.FIS')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# test the trained fis\n",
    "path = parent_directory +'/Data/elec/'\n",
    "file = 'ele2-4-1056-5.tst'\n",
    "test_data = Reader.read_elec_data(path, file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The testing took:  0.18211793899536133 seconds \n",
      "\n",
      "The RMSE is:  11908.5627717\n",
      "The MAE is:  76.8763225281\n",
      "The number of rules is  224\n"
     ]
    }
   ],
   "source": [
    "start = time.time()\n",
    "RMSE, MAE, _ = FIS.test(test_data, mf, overlap, target_centroids, feature_centroids, RB, target_col)\n",
    "print('The testing took: ', time.time() - start, 'seconds', '\\n')\n",
    "print('The RMSE is: ', RMSE)\n",
    "print('The MAE is: ' , MAE)\n",
    "print('The number of rules is ', len(RB))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test with SA, with a rule reduction of 20%"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# specify SA properties\n",
    "sa_alpha = 0.8 # keep 80 percent of the rules\n",
    "sa_flag = True\n",
    "sa_iterations = 200\n",
    "sa_plot = True\n",
    "# A name for the FIS file\n",
    "FIS_name='Demo_SA_elec'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZkAAAEZCAYAAABFFVgWAAAABHNCSVQICAgIfAhkiAAAAAlwSF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N7a/xv9cuiIg3ct/l8X22dOH4enZC0mCygJkZEbV7Fhv277MK\nIfMEcKCk/SUNIXtawL1NrlO/IWn79CkHSTsAJ5Dd91S7oRa2vqHW2ie2HjOod/3uBSalr7AYQ7oh\nuaxK9iNbXc/0h7DmDOD5tOzr2bmObpiHXv77HPBfvxwRmyRdAswlC9XbI2Jhk6vVn+wB/ExSkP17\n+VFEzJX078BsSZ8l3VDbzEr2ZZJ+DLQAu0h6BZgKfAf4SdvrFxELJM0GFpDdkHyRv21va3Wu53GS\njiCbCbkYuBB8PTuTbpj/C+A5SU+z5Yb5a2jn/++eXE/fjGlmZoWpQneZmZk1iUPGzMwK45AxM7PC\nOGTMzKwwDhkzMyuMQ8bMzArjkDFrEEmb0mPmn07//WoD972/pOcatT+zsgz4mzHNSrQ+PeOtKL6p\nzfodt2TMGqfd79WQ9LKkayTNl/SopANS+f6S/iU9OfhXkvZJ5btL+qdU/rSkj6ddDZZ0q6TnJc1R\n9tXjZn2aQ8ascbZr0102Mffe6og4HLgZqD0j6m+BH6YnB/84/QxwI9CayscDL6Tyg4C/jYgPAWuB\nPy/4fMx6zY+VMWsQSW9FxI7tlL8MHBcRi9MTb1+LiN0kvQHsmZ6vNxh4NSJ2l/Q6MDp9yV5tH/sD\nc9M3FZLGewZHxN+UcnJmPeSWjFk5os5yd7yXW96Ex1StH3DImDVOR991/un030nAI2n5YeCstPwZ\n4Ndp+QHgIgBJgyTVWkf+bnrrd/xJyKxxhkl6iiwMApgTEVek93aW9CzwLluC5QvADyV9BXgD+MtU\n/kXgVkmTgY3A58i+7dF929bveEzGrGBpTOaoiFjV7LqYlc3dZWbF8yc5qyy3ZMzMrDBuyZiZWWEc\nMmZmVhiHjJmZFcYhY2ZmhXHImJlZYRwyZmZWmP8P/bORlNZfCdwAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x101acf898>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The training took:  149.18697690963745 seconds \n",
      "\n"
     ]
    }
   ],
   "source": [
    "# train the FIS \n",
    "start = time.time()\n",
    "FIS.train(FIS_name, data, target_col, mf, Ncentroids, overlap, \n",
    "          alpha = sa_alpha , sa = sa_flag, iterations = sa_iterations, sa_plot = sa_plot)\n",
    "print('The training took: ', time.time() - start, 'seconds', '\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# read in the trained FIS\n",
    "method, mf, overlap, target_centroids, feature_centroids, RB = FIS.read(FIS_name +'.FIS')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The testing took:  0.1491241455078125 seconds \n",
      "\n",
      "The RMSE is:  29528.2763733\n",
      "The MAE is:  108.260314317\n",
      "The number of rules is  179\n"
     ]
    }
   ],
   "source": [
    "start = time.time()\n",
    "RMSE, MAE, _ = FIS.test(test_data, mf, overlap, target_centroids, feature_centroids, RB, target_col)\n",
    "print('The testing took: ', time.time() - start, 'seconds', '\\n')\n",
    "print('The RMSE is: ', RMSE)\n",
    "print('The MAE is: ' , MAE)\n",
    "print('The number of rules is ' , len(RB))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
